//
//  Auction_Main_VC_WX.m
//  ZITHER
//
//  Created by weixin on 2019/5/27.
//  Copyright © 2019 weixn. All rights reserved.
//

#import "Auction_Main_VC_WX.h"
#import "Auction_Main_Tbv_WX.h"
#import "Auction_TitleSelectMore_View_WX.h"
#import "Auction_ContactCustomerService_View_Wx.h"
#import "Auction_ContactCustomerService_View_Wx.h"

#import "ReportView.h"
#import "ZYShareView.h"
#import <UShareUI/UShareUI.h>



@interface Auction_Main_VC_WX ()


@property (nonatomic,strong)Auction_Main_Tbv_WX * tbv;

@property (nonatomic,strong)Auction_TitleSelectMore_View_WX * backView;
@property (nonatomic,strong)Auction_ContactCustomerService_View_Wx * Wechat;



@end

@implementation Auction_Main_VC_WX

- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = HexColor(0xf5f5f5);
    [self setNav];
    [self setMasonry];
}

-(void)setNav{
    [self.baseNavigationView setHiddenNav:NO VC:self];
    [self.baseNavigationView NavigationBarStyle:4];
    [[self.baseNavigationView.NavigationViewTitleLeft.rightBtn addTag]subscribeNext:^(id  _Nullable x) {
        [self.backView show];
    }];
}
- (Auction_TitleSelectMore_View_WX *)backView{
    if (!_backView) {
        _backView = [[Auction_TitleSelectMore_View_WX alloc]initWithFrame:CGRectMake(0,0, kScreenW, kScreenH)];
        @weakify(self);
        [_backView setBlock:^(NSInteger index, NSArray * _Nonnull arrTitle, NSArray * _Nonnull arrImg) {
            @strongify(self);
            if (100 == index  ) {
                [self.Wechat show];
            }else if (101 == index){
                [self showZYShare];
            }
        }];
    }
    return _backView;
}
-(void)setMasonry{

    [self.tbv mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.view).offset(NaviHeight);
        make.left.right.equalTo(self.view).offset(0);
        make.bottom.equalTo(self.view).offset(-49-kBottomSafeHeight);
    }];
    
    
}

- (Auction_ContactCustomerService_View_Wx *)Wechat{
    if (!_Wechat) {
        _Wechat = [[Auction_ContactCustomerService_View_Wx alloc]initWithFrame:CGRectMake(0,0, kScreenW, kScreenH)];
    }
    return _Wechat;
} 


-(Auction_Main_Tbv_WX *)tbv{
    if (!_tbv) {
        _tbv = [[Auction_Main_Tbv_WX alloc]initializeFrame:CGRectZero isMj:2 isEstimatedRowHeight:YES addRegisterNib:@[@"Auction_MainHead_TbvCell_WX",@"Auction_MainColumn_TbvCell_WX",@"Auction_performanceSpecial_TbvCell_WX"]];
        [self.view addSubview:_tbv];
    }
    return _tbv;
}





-(void)showZYShare{
    
    NSMutableArray *shareItemsArray = [[NSMutableArray alloc]init];
    NSMutableArray *functionItemsArray = [[NSMutableArray alloc]init];
    NSArray *shareItemsTitleArray = @[@"分享朋友圈",@"分享微信",@"分享QQ",@"分享QQ空间",@"分享微博"];
    NSArray *shareItemsTitle2Array = @[@"分享_朋友圈",@"分享_微信",@"分享_qq",@"分享_QQ空间",@"分享_微博"];

    
    NSArray *shareItemsTitle3Array = @[@"2",@"1",@"4",@"5",@"0"];
    NSArray *functionItems1Array = @[@"分享链接",@"举报",@"屏蔽用户"];
    NSArray *functionItems2Array = @[@"分享_链接",@"更多_举报",@"用户_屏蔽"];
    NSArray *functionItems3Array = @[@"1024",@"1025",@"1026"];
    
    if ([kUSER_INFO_MANAGER.userId isEqualToString:@"未知数据"]) {
        functionItems1Array = @[@"分享链接",@"举报"];
        functionItems2Array = @[@"分享_链接",@"更多_举报"];
        functionItems3Array = @[@"1024",@"1025"];
    }
    
    for (int i = 0; i<shareItemsTitleArray.count; i++) {
        if ([[UMSocialManager defaultManager]isInstall:i]) {
            ZYShareItem *item = [ZYShareItem itemWithTitle:shareItemsTitleArray[i]
                                                      icon:shareItemsTitle2Array[i]
                                                   handler:^{[self itemAction:shareItemsTitle3Array[i]];}];
            [shareItemsArray addObject:item];
        }
    }
    
    for (int i = 0; i<functionItems1Array.count; i++) {
        ZYShareItem *itemCustom1 = [ZYShareItem itemWithTitle:functionItems1Array[i]
                                                         icon:functionItems2Array[i]
                                                      handler:^{ [self itemAction:functionItems3Array[i]];
                                                      }];
        [functionItemsArray addObject:itemCustom1];
    }
    
    // 创建shareView
    ZYShareView *shareView = [ZYShareView shareViewWithShareItems:shareItemsArray
                                                    functionItems:functionItemsArray];
    // 弹出shareView
    [shareView show];
    
}


#pragma mark -

- (void)itemAction:(NSString *)title
{
    NSLog(@"%@", title);
    NSInteger index=  [title integerValue];
    if (index == 1024) {
        UIPasteboard * pastboard = [UIPasteboard generalPasteboard];
        pastboard.string = [NSString stringWithFormat:@"%@/#/share/pgc/%@",RootUrlWeb,@"未知数据"];
        
        [Tools showTips:@"复制链接成功"];
    }else if (index == 1025){
        if (!kUSER_INFO_MANAGER.userIsLogin) {
            [Tools pushSinge];
        }else{
            ReportView *rep = [[ReportView alloc]initWithFrame:CGRectMake(0,0, kScreenW, kScreenH)];
            rep.typeId = @"未知数据";
            rep.state = ReportViewStatePgc;
            [rep show];
        }
        
    }else if (index == 1026){
        [[AccountService loadUserRepelAdd:@"未知数据" reponseObjctClass:nil]subscribeNext:^(ResponseData* x) {
            if (x.success) {
                [Tools showTips:@"已屏蔽"];
            }else{
                [Tools showTips:x.errorInfo];
            }
        }];
    }else{
        if (!kUSER_INFO_MANAGER.userIsLogin) {
            [Tools pushSinge];
        }else{
            [self shareWebPageToPlatformType:index];
        }
    }
}

- (void)shareWebPageToPlatformType:(UMSocialPlatformType)platformType
{
    //创建分享消息对象
    UMSocialMessageObject *messageObject = [UMSocialMessageObject messageObject];
    
    NSString *name = [NSString stringWithFormat:@"%@ 的分享",kUSER_INFO_MANAGER.nickName];
    //创建网页内容对象
    UMShareWebpageObject *shareObject = [UMShareWebpageObject shareObjectWithTitle:name descr:@"未知数据" thumImage:[UIImage imageNamed:@"icon"]];
    //设置网页地址
    
    shareObject.webpageUrl = [NSString stringWithFormat:@"%@/#/share/pgc/%@",RootUrlWeb,@"未知数据"];
    
    messageObject.shareObject = shareObject;
    
    //调用分享接口
    [[UMSocialManager defaultManager] shareToPlatform:platformType messageObject:messageObject currentViewController:self completion:^(id data, NSError *error) {
        if (error) {
            NSLog(@"************Share fail with error %@*********",error);
        }else{
            NSLog(@"response data is %@",data);
        }
    }];
    
}

@end
